package com.Luoyi.springframework.core.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileSystemResource implements Resource{
    private final File file;
    private final String path;
    //构造器，不使用两个参数的构造器是因为保证参数一致性
    //如果传入的file参数与path不对应就会出现参数不一致导致的错误
    public FileSystemResource(File file) {
        this.file = file;
        this.path = file.getPath();
    }

    public FileSystemResource(String path) {
        this.file = new File(path);
        this.path = path;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return new FileInputStream(this.file);
    }
    public String getPath() {
        return path;
    }


}
